package com.kartoshka.painters 
{
	import com.kartoshka.interfaces.IPainter;
	import flash.display.Graphics;

	import com.kartoshka.painters.NullPainter;

	/**
	 * @author Alexander Zats, 2009
	 */
	public class CompositePainter extends NullPainter 
	{
		private var _painters : Array;
		
		public function CompositePainter( ...args )
		{
			super( );
			cornerRadius = NaN;
			_painters = [];
			addPainters( args );
		}
		
		public function addPainters( ...args ) : void
		{
			if ( args[ 0 ] is Array )
			{
				args = ( args[ 0 ] as Array ).concat();
			}
			for ( var i : int = 0; i < args.length; i++ )
			{
				_painters[ _painters.length ] = args[ i >> 0 ];
			}
		}

		override public function draw(graphics : Graphics, width : Number, height : Number) : void
		{
			for ( var i : int = 0; i < _painters.length ; i++ )
			{
				if ( !isNaN( cornerRadius ) )
				{
					( _painters[ i ] as IPainter ).cornerRadius = cornerRadius;
				}
				( _painters[ i ] as IPainter ).draw( graphics, width, height );
			}
		}
	}
}
